package flc.ast.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.AttachPopupView;

import flc.ast.R;
import flc.ast.databinding.DialogRankStyleBinding;
import stark.common.basic.base.BaseSmartDialog;

public class RankDialog extends AttachPopupView implements View.OnClickListener {

    private LinearLayout llAddFolder, llAlbumImport, llName, llSize, llTime;
    private ImageView ivName, ivSize, ivTime;


    public RankDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_rank_style;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        llAddFolder = findViewById(R.id.llAddFolder);
        llAlbumImport = findViewById(R.id.llAlbumImport);
        llName = findViewById(R.id.llName);
        llSize = findViewById(R.id.llSize);
        llTime = findViewById(R.id.llTime);
        ivName = findViewById(R.id.ivName);
        ivSize = findViewById(R.id.ivSize);
        ivTime = findViewById(R.id.ivTime);

        llAddFolder.setOnClickListener(this);
        llAlbumImport.setOnClickListener(this);
        llName.setOnClickListener(this);
        llSize.setOnClickListener(this);
        llTime.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llAddFolder:
                dismiss();
                if (listener != null) {
                    listener.clickAddFolder();
                }
                break;
            case R.id.llAlbumImport:
                dismiss();
                if (listener != null) {
                    listener.clickImport();
                }
                break;
            case R.id.llName:
                clearSelection();
                ivName.setVisibility(VISIBLE);
                dismiss();
                if (listener != null) {
                    listener.clickRankToName();
                }
                break;
            case R.id.llSize:
                clearSelection();
                ivSize.setVisibility(VISIBLE);
                dismiss();
                if (listener != null) {
                    listener.clickRankToSize();
                }
                break;
            case R.id.llTime:
                clearSelection();
                ivTime.setVisibility(VISIBLE);
                dismiss();
                if (listener != null) {
                    listener.clickRankToTime();
                }
                break;
            default:
                break;
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickAddFolder();

        void clickImport();

        void clickRankToName();

        void clickRankToSize();

        void clickRankToTime();
    }

    private void clearSelection() {
        ivName.setVisibility(INVISIBLE);
        ivSize.setVisibility(INVISIBLE);
        ivTime.setVisibility(INVISIBLE);
    }

}
